package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.DeviceAnnualFeeRecordService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.DeviceAnnualFeeRecordDto;
import com.huilian.iotbox.data.vo.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author: loong
 * @create: 2024-06-24 10:13
 **/

@RestController
@RequestMapping("/api/deviceAnnualFeeRecord")
@Slf4j
public class DeviceAnnualFeeRecordController extends UserInfoController {
    @Resource
    private DeviceAnnualFeeRecordService deviceAnnualFeeRecordService;

    @PostMapping("/pay")
    public ServerResponse pay(@RequestBody DeviceAnnualFeeRecordDto deviceAnnualFeeRecordDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        deviceAnnualFeeRecordDto.setUserInfo(userInfo);
        try {
            return ServerResponse.createBySuccess(deviceAnnualFeeRecordService.pay(deviceAnnualFeeRecordDto));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("流量卡充值失败" + e.getMessage());
            return ServerResponse.createByErrorMessage(e.getMessage());
        }
    }

    @PostMapping("/payNotice")
    public String payNotice(HttpServletRequest request) {
        try {
            return deviceAnnualFeeRecordService.payNotice(request);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            return "error";
        }
    }

    @PostMapping("/findList")
    public ServerResponse findList(@RequestBody DeviceAnnualFeeRecordDto deviceAnnualFeeRecordDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        deviceAnnualFeeRecordDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(deviceAnnualFeeRecordService.findList(deviceAnnualFeeRecordDto));
    }
}
